package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseUserRole;
import com.briup.mt.bean.BaseUserRoleExample;
import com.briup.mt.service.IBaseUserRoleService;
import org.springframework.stereotype.Service;
import com.briup.mt.dao.BaseUserRoleMapper;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BaseUserRoleServiceImpl implements IBaseUserRoleService {
    @Resource
    private BaseUserRoleMapper baseUserRoleMapper;
    @Override
    public BaseUserRole findById(long id) {
        return baseUserRoleMapper.selectByPrimaryKey(id);
    }


    @Override

    public List<BaseUserRole> query(Long userId, Long roleId) {

        BaseUserRoleExample example = new BaseUserRoleExample();
        if(!StringUtils.isEmpty(userId)){
            example.createCriteria().andUserIdEqualTo(userId);
        }
        if(!StringUtils.isEmpty(roleId)){
            example.createCriteria().andRoleIdEqualTo(roleId);
        }

        List<BaseUserRole> list = baseUserRoleMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseUserRole baseUserRole) {
        if(baseUserRole.getId() == null){
            baseUserRoleMapper.insert(baseUserRole);
        } else {
            baseUserRoleMapper.updateByPrimaryKey(baseUserRole);
        }
    }

    @Override
    public void deleteById(long id) {
baseUserRoleMapper.deleteByPrimaryKey(id);
    }
}
